CREATE PROCEDURE spAPI_User_CheckToken
(
	@Token VARCHAR(255)
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @ExpirationDate DATETIME
	DECLARE @Result INT
	
	SET @Result = 0
	
	SELECT @ExpirationDate = ExpirationDate
	FROM UserToken
	WHERE SecurityToken = @Token
	
	IF (@ExpirationDate IS NOT NULL)
	BEGIN
		IF (GETDATE() > @ExpirationDate)
			DELETE 
			FROM UserToken 
			WHERE SecurityToken = @Token
		ELSE
			SET @Result = 1
	END
	
	SELECT @Result AS Result
END	
GO

CREATE PROCEDURE spAPI_Category_GetAll
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @Result XML
	
	SELECT @Result = (SELECT CategoryId AS Id, CategoryName AS Name, ISNULL(CONVERT(VARCHAR(20), ParentId), '') AS ParentId
						FROM Category
						FOR XML AUTO, ROOT('Categories'))

	SELECT ISNULL(@Result, '') AS Result
END
GO	